﻿using Cache;
using DtoFw;
using DtoFw.Base;
using DtoFw.Query;
using DtoFw.Result;
using Microsoft.AspNetCore.Mvc;
using Service;
using System.Collections.Generic;

namespace SceneEvidenceAPI.Controllers
{
    /// <summary>
    /// 用户
    /// </summary>
    [Route("api/menu")]
    public class MainMenuController : BaseController
    {
        private readonly MainHomeService rep_home;
        private readonly MainRoleService _roleService;
        /// <summary>
        /// 菜单控制器
        /// </summary>
        /// <param name="home"></param>
        public MainMenuController(MainHomeService home, MainRoleService roleService)
        {
            rep_home = home;
            _roleService = roleService;
        }
        /// <summary>
        /// 获取角色菜单
        /// </summary>
        /// <param name="RoleId">角色ID</param>
        /// <returns></returns>
        [HttpGet("get/{RoleId}/role")]
        public BaseGenericResult<List<RoleMenuResult>> QueryRoleMenus(long RoleId = 0)
        {
            var user = TokenHelper.GetTokenInfo<TokenData>(User);
            if (RoleId < 1)
                RoleId = user.RoleId;
            return rep_home.QueryVueRoleMenus(new MenuQuery()
            {
                RoleId = RoleId,
                Page = 1,
                PageSize = 1000
            });
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name = "requestDto" ></ param >
        [HttpGet("get/pager")]
        public BaseGenericResult<Pager<MenuInfoResult>> GetPager([FromQuery] MenuQuery query)
        {
            return rep_home.GetPager(query);
        }
        /// <summary>
        /// 根据级别查询菜单列表
        /// </summary>
        /// <param name="level">菜单级别</param>
        /// <returns></returns>
        [HttpGet("get/{level}/level")]
        public BaseGenericResult<List<MenuLevelResult>> QueryToLevel(int level = 0)
        {
            return rep_home.QueryToLevel(level);
        }
        /// <summary>
        /// 新增菜单
        /// </summary>
        /// <param name="query">请求对象</param>
        /// <returns></returns>
        [HttpPost("post")]
        public BaseResult Post([FromBody] MenuInfo info)
        {
            return rep_home.Post(info);
        }
        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="query">请求对象</param>
        /// <returns></returns>
        [HttpPut("put")]
        public BaseResult Put([FromBody] MenuEditInfo info)
        {
            return rep_home.Put(info);
        }
        /// <summary>
        /// 移除菜单
        /// </summary>
        /// <param name="requestDto"></param>
        /// <returns></returns>
        [HttpDelete("delete")]
        public BaseResult Delete([FromBody]DeleteDto query)
        {
            return rep_home.Delete(query);
        }
        /// <summary>
        /// 根据Id查询菜单列表
        /// </summary>
        /// <param name="requestDto"></param>
        /// <returns></returns>
        [HttpGet("get")]
        public BaseGenericResult<MenuEditInfo> QueryModel(long Id)
        {
            return rep_home.QueryModel(Id);
        }
        /// <summary>
        /// 获取权限分配菜单
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("get/menus/tree")]
        public BaseGenericResult<RoleMapMenuResult> GetMealsTree()
        {
            return _roleService.GetMealsTree();
        }
    }
}
